<!-- ----------首页 ---------------->
<template>
	<view v-if="mainList.length" class="homePage">
		<view class="homePage_t">
			<image class="background" src="/static/image/homePage/bcg_img.png" mode="widthFix" />

			<swiper
				class="swiper"
				:indicator-dots="true"
				:autoplay="true"
				indicator-active-color="#2a62ff"
				:interval="3000"
				:duration="1000"
				:style="{
					margin: `0 30rpx`,
					borderRadius: `12rpx`,
					overflow: `hidden`,
				}"
			>
				<swiper-item>
					<image
						:style="{ width: `100%`, height: `100%`, borderRadius: `12rpx` }"
						src="/static/image/homePage/swiper1.png"
					/>
				</swiper-item>
				<swiper-item>
					<image
						:style="{ width: `100%`, height: `100%`, borderRadius: `12rpx` }"
						src="/static/image/homePage/swiper2.png"
						class="banner"
					/>
				</swiper-item>
			</swiper>
		</view>
		<view class="news">
			<image src="/static/image/homePage/news_icon.png" />
			<view class="news_swiper">
				<swiper
					class="swiper"
					autoplay="true"
					interval="3000"
					duration="500"
					vertical="true"
					circular="true"
				>
					<block v-for="(item, index) in newsList" :key="index">
						<swiper-item>
							<view class="swiper-item uni-bg-red">
								{{ item }}
							</view>
						</swiper-item>
					</block>
				</swiper>
			</view>
		</view>
		<navigator hover-class="none" url="/pages/mine/share" class="banner2">
			<image src="/static/image/homePage/banner2.png" />
		</navigator>
		<view class="list">
			<view class="list_title">
				<view class="title">产品类型</view>
				<!-- <view class="line" /> -->
			</view>
			<view v-for="(item, index) in mainList" :key="index" class="list_item">
				<image src="/static/image/homePage/list_bcg.png" />
				<view class="item_content">
					<view class="item_l">
						<view class="item_title">{{ item.name }}</view>
						<view class="price">
							<text class="red_price">
								{{ Number(item.price).toFixed(0) }} {{ item.shb }}
							</text>
						</view>
						<text class="color-666 fs-24">
							{{ `生效日期 ${formatDate(item.addtime * 1000, "Y-M-D")}` }}
						</text>
					</view>
					<navigator
						:url="`/pages/product/productDetail?id=${item.id}&name=${item.name}&content=${item.content}&price=${item.price}`"
						class="btn"
					>
						立即购买
					</navigator>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { formatDate } from "@/static/utils";

	export default {
		data() {
			return {
				newsList: [
					"感谢广大用户对平台的理解与支持！我们将继续为大家提供",
					"但愿人长久，千里共婵娟",
				],

				mainList: [],
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
			};
		},
		onLoad() {
			uni.showToast({ title: "Loading...", icon: "loading" });
			this.$request.get("/Shop/Index/index").then(({ data }) => {
				uni.hideToast();
				this.mainList = data;
			});
		},
		methods: {
			formatDate,
			handleToMsg() {
				uni.navigateTo({
					url: `/pages/index/news`,
				});
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;
	}

	.homePage {
		position: relative;

		.homePage_t {
			width: 100%;
			position: relative;
			padding-top: 30rpx;
			.background {
				position: absolute;
				width: 100%;
				top: 0;
			}
		}

		.news {
			width: 690rpx;
			height: 50rpx;
			display: flex;
			align-items: center;
			line-height: 50rpx;
			font-size: 24rpx;
			padding: 0 12rpx 0 20rpx;
			box-sizing: border-box;
			margin: 30rpx auto;
			background-color: #ffffff;
			border-radius: 10rpx;

			image {
				width: 24rpx;
				height: 22rpx;
				margin-right: 20rpx;
			}

			.news_swiper {
				flex-grow: 1;

				.swiper,
				.swiper-item {
					height: 50rpx;
					width: 100%;
					color: #2a62ff;
				}
			}

			.swiper,
			.swiper-item {
				height: 50rpx;
				width: 614rpx;
				color: #2a62ff;
			}
		}

		.banner2 {
			display: flex;
			justify-content: center;

			image {
				width: 690rpx;
				height: 140rpx;
			}
		}

		.list {
			padding: 20rpx 30rpx 10rpx;
			box-sizing: border-box;

			.list_title {
				height: 46rpx;
				display: flex;
				align-items: flex-end;
				position: relative;
				margin-bottom: 20rpx;

				.title {
					color: #1a1a1a;
					font-size: 34rpx;
					font-weight: 600;
					position: absolute;
					left: 0;
					top: 0;
					z-index: 2;
				}

				.line {
					width: 139rpx;
					height: 10rpx;
					background: linear-gradient(to top, #2a62ff, #ffffff);
					border-radius: 4rpx;
					margin-left: 10rpx;
				}
			}

			.list_item {
				width: 683rpx;
				height: 210rpx;
				margin: 0 0 20rpx 9rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}

				.item_content {
					width: 100%;
					height: 100%;
					padding: 29rpx 20rpx 30rpx 19rpx;
					box-sizing: border-box;
					position: absolute;
					left: 0;
					top: 0;
					z-index: 2;
					display: flex;
					justify-content: space-between;
					align-items: flex-end;

					.item_l {
						width: 442rpx;

						.item_title {
							width: 100%;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							color: #1a1a1a;
							font-size: 32rpx;
						}

						.price {
							font-size: 24rpx;
							color: #666666;
							line-height: 23rpx;
							padding: 30rpx 0;

							.red_price {
								font-size: 32rpx;
								color: #ff3608;
								margin-right: 10rpx;
							}
						}

						.sxrq {
							font-size: 24rpx;
							color: #666666;
							line-height: 22rpx;
						}
					}

					.btn {
						width: 140rpx;
						height: 42rpx;
						background-color: #2a62ff;
						border-radius: 21rpx;
						color: #ffffff;
						font-size: 24rpx;
						line-height: 42rpx;
						text-align: center;
					}
				}
			}
		}
	}
</style>
